package web.suzy.oj.service.oj.impl;

import org.springframework.stereotype.Service;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.exception.StatusSystemErrorException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.common.result.ResultStatus;
import web.suzy.oj.manager.oj.AccountManager;
import web.suzy.oj.pojo.dto.ChangeEmailDTO;
import web.suzy.oj.pojo.dto.ChangePasswordDTO;
import web.suzy.oj.pojo.dto.CheckUsernameOrEmailDTO;
import web.suzy.oj.pojo.vo.*;
import web.suzy.oj.service.oj.AccountService;

import javax.annotation.Resource;

/**
 * YangSuzy 软件工作室
 * 类名: AccountServiceImpl
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/14 18:03
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountManager accountManager;

    /**
     * 方法名: checkUsernameOrEmail
     * 描述: 检查用户名或邮箱是否存在
     *
     * @param checkUsernameOrEmailDto
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.CheckUsernameOrEmailVO>
     * @date 2022/11/14 18:04
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<CheckUsernameOrEmailVO> checkUsernameOrEmail(CheckUsernameOrEmailDTO checkUsernameOrEmailDto) {
        return ResultBean.successResponse(accountManager.checkUsernameOrEmail(checkUsernameOrEmailDto));
    }

    /**
     * 方法名: changePassword
     * 描述: 修改密码
     *
     * @param changePasswordDto
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.ChangeAccountVO>
     * @date 2022/11/14 20:23
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<ChangeAccountVO> changePassword(ChangePasswordDTO changePasswordDto) {
        try {
            return ResultBean.successResponse(accountManager.changePassword(changePasswordDto));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        } catch (StatusSystemErrorException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.SYSTEM_ERROR);
        }
    }

    /**
     * 方法名: changeEmail
     * 描述: 修改邮箱
     *
     * @param changeEmailDto
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.ChangeAccountVO>
     * @date 2022/11/15 11:54
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<ChangeAccountVO> changeEmail(ChangeEmailDTO changeEmailDto) {
        try {
            return ResultBean.successResponse(accountManager.changeEmail(changeEmailDto));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        } catch (StatusSystemErrorException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.SYSTEM_ERROR);
        }
    }

    /**
     * 方法名: changeUserInfo
     * 描述: 修改用户信息
     *
     * @param userInfoVo
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserInfoVO>
     * @date 2022/11/15 12:13
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<UserInfoVO> changeUserInfo(UserInfoVO userInfoVo) {
        try {
            return ResultBean.successResponse(accountManager.changeUserInfo(userInfoVo));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }

    /**
     * 方法名: getUserHomeInfo
     * 描述: 获取用户主页信息
     *
     * @param uid      用户ID
     * @param username 用户名
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserHomeVO>
     * @date 2022/11/23 14:38
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<UserHomeVO> getUserHomeInfo(String uid, String username) {
        try {
            return ResultBean.successResponse(accountManager.getUserHomeInfo(uid, username));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }

    /**
     * 方法名: getUserCalendarHeatmap
     * 描述: 获取用户主页的提交热力图
     *
     * @param uid      用户ID
     * @param username 用户名
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserCalendarHeatmapVO>
     * @date 2022/11/23 16:13
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<UserCalendarHeatmapVO> getUserCalendarHeatmap(String uid, String username) {
        try {
            return ResultBean.successResponse(accountManager.getUserCalendarHeatmap(uid, username));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }
}
